var e = getApp(), n = require("../../utils/data.js");

Page({
    data: {
        username: null,
        password: null
    },
    onLoad: function(e) {
        var n = wx.getUpdateManager();
        n.onCheckForUpdate(function(e) {
            console.log(1.6), console.log(e.hasUpdate);
        }), n.onUpdateReady(function() {
            wx.showModal({
                title: "更新提示",
                content: "新版本已经准备好，是否重启应用？",
                success: function(e) {
                    e.confirm && n.applyUpdate();
                }
            });
        }), n.onUpdateFailed(function() {});
    },
    onReady: function() {},
    onShow: function() {
        wx.getSetting({
            success: function(e) {
                e.authSetting["scope.userLocation"] || wx.authorize({
                    scope: "scope.userLocation",
                    success: function() {}
                });
            }
        });
        var e = wx.getUpdateManager();
        e.onCheckForUpdate(function(e) {
            console.log(1.6), console.log(e.hasUpdate);
        }), e.onUpdateReady(function() {
            wx.showModal({
                title: "更新提示",
                content: "新版本已经准备好，是否重启应用？",
                success: function(n) {
                    n.confirm && e.applyUpdate();
                }
            });
        }), e.onUpdateFailed(function() {});
    },
    onHide: function() {},
    onUnload: function() {},
    loginBtnClick: function() {
        wx.request({
            url: n.getInterfaceData() + "login.action",
            data: {
                username: this.data.username,
                password: this.data.password
            },
            header: {
                "content-type": "application/json"
            },
            success: function(n) {
                if (console.log(n.data), "login" == n.data) wx.showToast({
                    icon: "loading",
                    title: "绑定失败"
                }); else {
                    wx.showToast({
                        icon: "success",
                        title: "绑定成功"
                    });
                    var a = n.data[0].person_level;
                    console.log(a), e.appData.userinfo = {
                        username: n.data[0].person_name,
                        personid: n.data[0].person_id,
                        person_uname: n.data[0].person_uname,
                        persontype: n.data[0].person_level
                    };
                    try {
                        wx.setStorageSync("username", n.data[0].person_name), wx.setStorageSync("personid", n.data[0].person_id), 
                        wx.setStorageSync("person_uname", n.data[0].person_uname), wx.setStorageSync("persontype", n.data[0].person_level);
                    } catch (e) {}
                    wx.switchTab({
                        url: "../index/index"
                    });
                }
            }
        });
    },
    usernameInput: function(e) {
        this.setData({
            username: e.detail.value
        });
    },
    passwordInput: function(e) {
        this.setData({
            password: e.detail.value
        });
    }
});